﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using tuwien.auto.eibclient;

namespace KNXFramework.KNXObjects.ValueObjects
{
    internal class ScaledObjectValue : U8ObjectValue  
    {
        public ScaledObjectValue(string value) : base(value)
        {
            uint val;
            if (uint.TryParse(value, out val))
            {
                if (val > 100)
                    throw new ApplicationException("ScaledObjectValue: Value shoud be contained between 0 and 100. Val : " + value);

                m_Value = (uint)val * 255 / 100;

            }
            else
                throw new ApplicationException("ScaledObjectValue: Cannot convert to uint. Val : " + value);
        }
        public ScaledObjectValue(EIBBuffer buffer) : base(buffer)
        {            
        }
        public override string ToString()
        {            
            return ((float)m_Value * 100 / 255).ToString("#.###");
        }
    }
}
